package com.example.searchcenter.center;

import java.util.ArrayList;
import java.util.HashMap;

import com.example.searchcenter.R;
import com.example.searchcenter.helper.ImageLoader;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;

@SuppressLint("InflateParams")
public class CenterAdapter extends BaseAdapter implements Filterable {
    
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 
    
    public CenterAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.list_row, null);

        TextView title = (TextView)vi.findViewById(R.id.title); 
        TextView id_center = (TextView)vi.findViewById(R.id.id_center); 
        TextView date = (TextView)vi.findViewById(R.id.createDate); 
        TextView address = (TextView)vi.findViewById(R.id.address); 
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); 
        
        HashMap<String, String> center = new HashMap<String, String>();
        center = data.get(position);
        
        // Setting all values in listview
        title.setText(center.get(Home.TAG_NAME));
        id_center.setText(center.get(Home.TAG_ID_CENTER));
        address.setText("Địa chỉ: Số "+center.get(Home.TAG_NO) + ", Đường " + center.get(Home.TAG_STREET) 
        		+ ", phường " + center.get(Home.TAG_WARD) + ", quận " + center.get(Home.TAG_DISTRICT)
        		+ ", "+center.get(Home.TAG_CITY));
        date.setText("Ngày tạo: "+ center.get(Home.TAG_CREATEDATE));
        imageLoader.DisplayImage(center.get(Home.TAG_THUMBNAIL), thumb_image);
        return vi;
    }

	@Override
	public Filter getFilter() {
		// TODO Auto-generated method stub
		return null;
	}
    
}